package com.yxy.http;

import com.yxy.http.util.MessageBackup;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 主程序入口类。
 */
public class Main {
    /*public static void main(String[] args) {
        if (args.length != 1) {
            System.out.println("请加参数s或c代表服务端或客户端启动程序。");
            System.exit(1);
        }

        switch (args[0].toLowerCase()) {
            case "s":
                Server server = new Server();

                break;
            case "c":
                Client client = new Client();

                break;
            default:
                System.out.println("请加参数s或c代表服务端或客户端启动程序。");
                break;
        }

    }*/
    private final Logger logger = LogManager.getLogger();
    /**
     * 文件上传
     */
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(1);//控制并发线程数
        for (int i = 0; i < 1; i++)//任务提交次数
            executorService.execute(new Main().new Task());

      /*  executorService.shutdown();
        while (!executorService.isTerminated()) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }*/
    }
    /**
     * 模拟高并发，使用多线程进行测试
     */
    public class Task implements Runnable {

        String fsPath;
        String url = "http://192.168.105.235:8080/upload";
        {
            //String   strDicPath = MessageBackup.getDirectory();
            File file= file=new File("C:/chs-software/file01/file");
            if(file.isDirectory()) {
                File[] fs=file.listFiles();
                for(int i=0;i<fs.length;i++){
                    fsPath=fs[i].getAbsolutePath();
                    run();
                }
            }
        }

        @Override
        public void run() {
            try {
                new Client().uploadFile(url, new File(fsPath));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * 文件下载
     * @param args
     */
   /* public static void main(String[] args){
        String url = "http://192.168.106.93:8080/download";
        new Client().download(url);
    }*/
}
